import socketserver as ss
import socket as soc
import os

port=6666
host = soc.gethostbyname(soc.gethostname())
host1='127.0.0.1'


class Run_server(ss.StreamRequestHandler):
    def handle(self):
        print('已连接：' + str(self.client_address))
        orderlist={'1v1仿真\n':self.test1v1,'1v2仿真\n':self.test1v2,
                   '1v3仿真\n':self.test2v1,'':self.exit}
        self.control=True
        while(self.control):
            order = self.rfile.readline().decode()
            print('接收到的命令为',order)
            orderlist[order]()


    def test1v1(self):
        os.system('python Env\\1v1test.py')

    def test1v2(self):
        os.system('python Env\\1v2test.py')

    def test2v1(self):
        os.system('python Env\\2v1test.py')

    def exit(self):
        self.control=False

if __name__=="__main__":
    server = ss.ThreadingTCPServer((host1, port), Run_server)  # 多进程处理
    print('等待连接')
    server.serve_forever()